<%@page import="java.util.HashMap"%>
<%@page import="server.Utils"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="java.util.ResourceBundle"%>
<%@page import="com.mongodb.DBObject"%>
<%@page import="com.mongodb.DBCursor"%>
<%
DBCursor cu = (DBCursor) request.getAttribute("cu");
String keyword = (String) request.getAttribute("keyword");
ResourceBundle resource = ResourceBundle.getBundle("google");

String[] arrs = (String[])request.getAttribute("arr");
String domain = (String) request.getAttribute("domain");
HashMap<String,String> listGoogle = (HashMap<String,String>) request.getAttribute("listGoogle");
%>
<%
	response.setCharacterEncoding("UTF-8");
%>
<%
String title = keyword+" - wordtrends.net";
String description = "ranking of the "+keyword+" on the search engines to list the first 10 results returned";
String keywords = "wordtrends,keyword,website,tool,ranking,check keyword"+keyword;
%>
<%
	response.setCharacterEncoding("UTF-8");
%>
<jsp:include page="/layout/header.jsp">
	<jsp:param name="title" value="<%=title %>"/>
	<jsp:param name="description" value="<%=description %>"/>
	<jsp:param name="keywords" value="<%=keywords %>"/>
	<jsp:param name="index" value="true"/>
</jsp:include>
	<div class="body">
		<div class="adv">
			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1271973886625217";
			/* domainworlds 336x280 */
			google_ad_slot = "4751386823";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1271973886625217";
			/* domainworlds 336x280 */
			google_ad_slot = "4751386823";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1271973886625217";
			/* domainworlds 336x280 */
			google_ad_slot = "4751386823";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
		</div>
		<ul class="new_search">
			
		</ul>
		<div class="clear"></div>
		<div id='content'>
			<h1>Top ranked website for "<%=keyword.replaceAll("[+]+"," ") %>"</h1>
			<%
			if(cu != null && cu.size() > 0)
			{
			%>
			
			<%
			int k=0;
			while(cu.hasNext())
			{
				DBObject dbObject = (DBObject) cu.next();
				String[] arr = dbObject.get("result").toString().split(" ");
			%>
			<div class="box border<%=k%>">
				<div class="box_top order<%=k%>"><%=resource.getString(dbObject.get("domain").toString()) %></div>
				<ul dir="ltr">
					<%
					for(int j=0;j<arr.length;j++)
					{
						if(Pattern.matches("^http://[\\w\\W]+", arr[j]))
						{
					%>
						<li><a href="<%=arr[j]%>" rel="nofollow" target="_blank" title="<%=Utils.fomatDomain(arr[j]) %>" <%=(Utils.fomatDomain(arr[j]).equals(domain))?"style='color:red;'":"" %>><%=Utils.fomatDomain(arr[j]) %></a></li>
					<%
						}
					}
					%>
					
				</ul>
			</div>
			<%
				k++;
				if(k%5==0)
					k=0;
				
			}
			%>
			<%
			} else {
			%>
			<%
			int i=0;
			int k=0;
			for (String key : listGoogle.keySet()) {
				if(arrs[i] != null)
				{
					String[] arr = arrs[i].split(" ");
			%>
				<div class="box border<%=k%>">
					<div class="box_top order<%=k%>"><%=key %></div>
					<ul dir="ltr">
						<%
						for(int j=0;j<arr.length;j++)
						{
							if(Pattern.matches("^http://[\\w\\W]+", arr[j]))
							{
						%>
							<li><a href="<%=arr[j]%>" rel="nofollow" target="_blank" title="<%=Utils.fomatDomain(arr[j]) %>" <%=(Utils.fomatDomain(arr[j]).equals(domain))?"style='color:red;'":"" %>><%=Utils.fomatDomain(arr[j]) %></a></li>
						<%
							}
						}
						%>
						
					</ul>
				</div>
			<%
				k++;
				if(k%5==0)
					k=0;
				}
				i++;
			}
			%>
			<%
			}
			%>
			<div class="clear"></div>
		</div>
		
		<%@ include file='/element/new_keyword.jsp'%>
		<div class="clear"></div>
	</div>
<script src="/js/jquery.js"></script>	
<script src="/js/check.js"></script>
<%@ include file='/layout/footer.jsp'%>	